package com.kaishengit.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.entity.Goal;
import com.kaishengit.entity.Project;
import com.kaishengit.service.GoalService;
import com.kaishengit.service.ProjectService;

public class ProjectListView extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doPost(request,response);
	
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		ProjectService projectService = new ProjectService();
		
		List<Project> listproject = projectService.findAll();
		
		HashMap numbers = new HashMap();
		
		GoalService goalService = new GoalService();
		
		for(Project project : listproject) {
			List<Goal> listgoal = goalService.findGoalnamesByProjectname(project.getName());
			numbers.put(project.getName(),listgoal);
		}
		
		request.setAttribute("numbers", numbers);
		request.setAttribute("listproject",listproject);
		
		request.getRequestDispatcher("WEB-INF/views/projectlist.jsp").forward(request, response);

		
	}

}
